﻿Public Class frmMain
    Private _fwList As List(Of clsFW)
    Private _text As clsText
    Private _debugText As clsText
    Private _sparkEmitter As clsSparkEmitter

    Private _mousePos As Drawing.PointF
    Private _mouseLeft As Boolean
    Private _mouseRight As Boolean

    Private Sub pRenderTicker_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pRenderTicker.Tick
        Me.Refresh()
    End Sub

    Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.Space
                Dim x As Single = Me.ClientSize.Width / 2.0 + clsSim.RndRange(-200, 200)
                Dim y As Single = Me.ClientSize.Height - 10.0
                Dim newFW As New clsFW(New Drawing.PointF(x, y), clsSim.RndColor, 400, 3.0)
                newFW.Launch(New Drawing.PointF(clsSim.RndRange(-50, 50), clsSim.RndRange(100, 200)), clsSim.RndRange(1.5, 4.0), clsSim.RndRange(100.0, 250.0))
                _fwList.Add(newFW)
            Case Keys.Enter
                If _text Is Nothing Then
                    _text = New clsText("♥ ♥ V i v i ♥ S c h a t z i ♥ ♥", _
                            New Drawing.PointF(Me.ClientSize.Width / 2.0, Me.ClientSize.Height / 2.0), _
                            New Drawing.Font("Courier New", 20, FontStyle.Bold), _
                            clsSim.RndColor, _
                            15.0, _
                            6.0, _
                            1.0)
                Else
                    _text.remove()
                    _text = Nothing
                End If
                
        End Select
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        pRenderTicker.Interval = 10
        pRenderTicker.Enabled = True
        clsSimTime.SimulationSpeed = 1.0

        _fwList = New List(Of clsFW)
        _sparkEmitter = New clsSparkEmitter(30.0)

        '_debugText = New clsText("---", _
        '                         New Drawing.PointF(40.0, 10.0), _
        '                         New Drawing.Font("Impact", 6), _
        '                         Color.Lime, _
        '                         5.0, _
        '                         0.0, 0.0)
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim g As Graphics = e.Graphics
        g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
        g.Clear(Color.Black)

        If _mouseLeft Then
            _sparkEmitter.Emit(_mousePos, 8)
        End If
        If _mouseRight Then
            _sparkEmitter.Emit(_mousePos, 8, True)
        End If

        For Each fw In _fwList
            fw.Draw(g)
        Next

        If _sparkEmitter IsNot Nothing Then
            _sparkEmitter.Draw(g)
        End If

        If _text IsNot Nothing Then
            _text.Draw(g)
        End If

        If _debugText IsNot Nothing Then
            _debugText.Draw(g, "TC-Count: " + clsSimTime.TimeControlCount.ToString)
        End If

        'MyBase.OnPaint(e)
    End Sub


    Private Sub frmMain_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        _mousePos = e.Location
        If e.Button = MouseButtons.Left Then
            _mouseLeft = True
        End If
        If e.Button = MouseButtons.Right Then
            _mouseRight = True
        End If
    End Sub
    Private Sub frmMain_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        If e.Button = MouseButtons.Left Then
            _mouseLeft = False
        End If
        If e.Button = MouseButtons.Right Then
            _mouseRight = False
        End If
    End Sub

    Private Sub frmMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If _mouseLeft Then
            _sparkEmitter.Emit(_mousePos, 8)
            _mousePos = e.Location
        End If
        If _mouseRight Then
            _sparkEmitter.Emit(_mousePos, 8, True)
            _mousePos = e.Location
        End If
    End Sub

    
End Class
